package org.jeecg.modules.online.desform.excel.converter.channel;

import org.jeecg.common.system.vo.DictModel;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.online.desform.excel.converter.FieldCommentConverter;

import java.util.List;
import java.util.Map;

/**
 * 预知型值转换
 * 提前知道了当前数据可能需要替换的所有字典值
 */
public class ForeseeConvert implements FieldCommentConverter {

    protected String model;

    protected List<DictModel> dictList;

    public String getModel() {
        return model;
    }

    public void setModel(String model) {
        this.model = model;
    }

    public List<DictModel> getDictList() {
        return dictList;
    }

    public void setDictList(List<DictModel> dictList) {
        this.dictList = dictList;
    }


    @Override
    public Object converterToVal(String txt) {
        if (oConvertUtils.isNotEmpty(txt)) {
            for (DictModel model : this.dictList) {
                if (model.getText().equals(txt)) {
                    return model.getValue();
                }
            }
        }
        return txt;
    }

    @Override
    public Object converterToTxt(String val) {
        if (oConvertUtils.isNotEmpty(val)) {
            for (DictModel model : this.dictList) {
                if (model.getValue().equals(val)) {
                    return model.getText();
                }
            }
        }
        return val;
    }

    @Override
    public Map<String, String> getConfig() {
        return null;
    }
}
